package com.situ.water_Invoice.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.situ.water_Invoice.mapper.IvIninvoiceMapper;
import com.situ.water_Invoice.mapper.IvInvoiceMapper;
import com.situ.water_Invoice.mapper.fpsyMapper;
import com.situ.water_Invoice.pojo.FPSY;
import com.situ.water_Invoice.pojo.IvIninvoice;
import com.situ.water_Invoice.pojo.IvInvoice;
import com.situ.water_system.pojo.SyEmp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
public class fpsyController {

    @Autowired
    fpsyMapper fpsyMapper;
    @Autowired
    IvIninvoiceMapper ivInInvoiceMapper;
    @Autowired
    IvInvoiceMapper ivInvoiceMapper;


    @ResponseBody
    @RequestMapping("/FPSY_MX")
    public List<FPSY> FPSYMX(){
        List<FPSY> list = fpsyMapper.FPSYMX();
        list.forEach(System.out::println);
        return list;
    }


    //发票_领用人
    @ResponseBody
    @GetMapping("FP_LYR")
    public List<SyEmp> FP_LYR() {
        List<SyEmp> syEmps = fpsyMapper.FP_LYR();
        System.out.println(syEmps);
        return syEmps;
    }



    @ResponseBody
    @GetMapping("/FPSYQKCX")
    public List<Map<String, Object>> FPSYQKCX(String empId, String startNo, String endNo, String useDateS, String useDateE, String used, String invalid, String archived, String invoiceType, String invoiceNo) {
        System.out.println("aaa");
        List<Map<String, Object>> maps = new ArrayList<>();
        if (startNo != "" || endNo != "") {
            maps = ivInInvoiceMapper.selectMaps(new QueryWrapper<IvIninvoice>() {{
                if (startNo != "") {
                    ge("startNo", startNo);
                }
                if (endNo != "") {
                    le("endNo", endNo);
                }
            }});

        } else if (useDateS != null || useDateE != null) {
            maps = ivInvoiceMapper.selectMaps(new QueryWrapper<IvInvoice>() {
                {
                    if (useDateS != "") {
                        gt("useDate", useDateS);
                    }
                    if (useDateE != "") {
                        lt("useDate", useDateE);
                    }
                }
            });
        } else {
            maps = ivInvoiceMapper.selectMaps(new QueryWrapper<IvInvoice>() {
                {
                    if (empId != "") {
                        eq("EmpID", empId);
                    }
                    if (used!=""){
                        if (used=="0"){
                            eq("used",used );
                        }else {
                            ge("used", used);
                        }
                    }
                    if(invalid!=""){
                        if (invalid=="0"){
                            eq("invalid",invalid );
                        }else {
                            ge("invalid", invalid);
                        }
                    }
                    if(archived!=""){
                        if (archived=="0"){
                            eq("archived",archived );
                        }else {
                            ge("archived", archived);
                        }
                    }
                    if(invoiceType!=""){
                        if (invoiceType=="0"){
                            eq("invoiceType",invoiceType );
                        }else {
                            ge("invoiceType", invoiceType);
                        }
                    }
                    if (invoiceNo!=""){
                        eq("invoiceNo", invoiceNo);
                    }
                }
            });
        }
        return maps;
    }

}
